#include <iostream>
#include <set>
#include <vector>
using namespace std;

int n,m;
vector<int> v[55];

signed main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        int k,a;
        cin>>k;
        for(int j=0;j<k;j++){
            cin>>a;
            v[i+1].push_back(a);
        }
        sort(v[i+1].begin(),v[i+1].end());
    }
    cin>>m;
    for(int i=0;i<m;i++){
        int a,b,similarNum = 0;
        set<int> s;
        cin>>a>>b;
        int j1 = 0,j2 = 0;
        while(j1<v[a].size()&&j2<v[b].size()){
            if(v[a][j1]<v[b][j2]){
                s.insert(v[a][j1]);
                j1++;
            }
            else if(v[b][j2]<v[a][j1]){
                s.insert(v[b][j2]);
                j2++;
            }
            else{
                s.insert(v[a][j1]);
                if(j1==0||v[a][j1]!=v[a][j1-1])    similarNum++;
                j1++;
                j2++;
            }
        }
        while(j1<v[a].size())    s.insert(v[a][j1++]);
        while(j2<v[b].size())    s.insert(v[b][j2++]);
        printf("%.1f\%\n",similarNum*1.0/s.size()*100);
    }
    return 0;
}
